<?php
    class StudentDormitoryListDAL{
        //获取学生列表
        public function getStudentInfo($grade,$major,$class,$search){
            $query="select tb_student_info_list.student_id,tb_student_info_list.name,tb_student_info_list.gender,
            grade,tb_major_list.major_name,tb_student_info_list.class,
            tb_apartment_info.apartment_name,tb_student_dormitory_roster.dormitory_id 
            from tb_student_dormitory_roster,tb_student_info_list,tb_major_list,tb_apartment_info 
            where tb_student_dormitory_roster.student_id=tb_student_info_list.student_id 
            and tb_student_dormitory_roster.status=1 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_dormitory_roster.apartment_id=tb_apartment_info.apartment_id 
            and tb_student_info_list.grade=:grade 
            and tb_student_info_list.major_id=:major_id 
            and tb_student_info_list.class=:class ".
            ($search==''?'':'and (tb_student_info_list.student_id=:search_id or tb_student_info_list.name=:search_name);');

            $pdo=myPDO::getInstance();
            $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
            $statement->bindValue(':grade',$grade);
            $statement->bindValue(':major_id',$major);
            $statement->bindValue(':class',$class);
            if(!$search==''){
                $statement->bindValue(':search_id',$search);
                $statement->bindValue(':search_name',$search);
            }

            if($statement->execute()){
                $result=$statement->fetchALL(PDO::FETCH_ASSOC);
            }

            return $result;
        }
    }
?>